package com.java46.front.dessertType.action;

import com.java46.admin.base.entity.GenericResult;
import com.java46.front.base.action.BaseAction;
import com.java46.front.base.exception.BusinessException;
import com.java46.front.dessertType.entity.DesserttypeEntity;
import com.java46.front.dessertType.service.DessertTypeService;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

import java.util.List;
import java.util.prefs.BackingStoreException;

public class DessertTypeAction extends BaseAction {
        private DessertTypeService dessertTypeService=new DessertTypeService();

        //查询甜品类型
        @Action(value="queryDessertType")
        public String queryDessertType(){
            List<DesserttypeEntity> allDessertType = dessertTypeService.getAllDessertType();
            if (allDessertType.size()==0){
                throw new BusinessException("天啊数据被外星人劫持啦...");
            }
            //返回json格式
            setSuccesResult(allDessertType);
            return "json";
        }
//       //添加甜品类型
//        private String typeName;
//        public String getTypeName() {
//            return typeName;
//        }
//        public void setTypeName(String typeName) {
//            this.typeName = typeName;
//        }
//        @Action(value = "addDesserttype",results = { @Result(name = "AddDesserTtype",location = "/detail/saveCuisine.jsp")})
//        public String  addDesserttype() {
//              System.out.println(typeName);
//              //拿到页面传入的数据存入实体
//                DesserttypeEntity desserttype = new DesserttypeEntity();
//                desserttype.setTypeName(typeName);
//            try {
//                dessertTypeService.addDessertType(desserttype);
//            } catch (BusinessException e) {
//                // 获取DessertTypeService中addDessertType方法中抛出的异常对象
//                // 获取异常对象的errorMessage属性
//                String errorMessage = e.getMessage();
//                // 放入session作用域，用于在页面获取
//                setSessionAttribute("errorMessage", errorMessage);
//                return "input";
//            } catch (BackingStoreException e) {
//                e.printStackTrace();
//            }
//            return "AddDesserTtype";
//        }
//
//        //删除甜品类型
//    @Action(value = "deleteDessertType")
//     public String deleteDessertType(int dessertTypeId){
//         System.out.println("dessertTypeId = " + dessertTypeId);
//         dessertTypeService.deleteDessertType(dessertTypeId);
//         return "";
//     }
}
